<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Writing Applets: Panel Applet Library Reference Manual</title>
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
<link rel="home" href="index.html" title="Panel Applet Library Reference Manual">
<link rel="up" href="index.html" title="Panel Applet Library Reference Manual">
<link rel="prev" href="index.html" title="Panel Applet Library Reference Manual">
<link rel="next" href="server-files.html" title="MateComponent Activation .server Files For Applets">
<meta name="generator" content="GTK-Doc V1.29 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle">
<td width="100%" align="left" class="shortcuts"></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><img src="up-insensitive.png" width="16" height="16" border="0"></td>
<td><a accesskey="p" href="index.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="server-files.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="chapter">
<div class="titlepage"><div><div><h1 class="title">
<a name="applet-writing"></a>Writing Applets</h1></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="sect1"><a href="applet-writing.html#hello-world">Hello World Applet</a></span></dt>
<dt><span class="sect1"><a href="server-files.html">MateComponent Activation .server Files For Applets</a></span></dt>
<dt><span class="sect1"><a href="applet-popups.html">Defining a Popup Context Menu</a></span></dt>
<dt><span class="sect1"><a href="panel-signals.html">Detecting Changes in the Panel.</a></span></dt>
<dt><span class="sect1"><a href="session-saving.html">Session/Preference Saving.</a></span></dt>
<dt><span class="sect1"><a href="multi-applets.html">Multiple Applets</a></span></dt>
</dl></div>
<p>Writing applets is very simple. You take some boiler plate
code like below, change a couple of things and write the code that
implements your widgetry. The hardest part is writing your widgetry -
and its completely up to yourself how hard that should be.
    </p>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="hello-world"></a>Hello World Applet</h2></div></div></div>
<p>As usual, following the pointless tradition of starting with
an example of how get 'Hello World' on the screen in some form, here's
just about the simplest applet you could write.
      </p>
<pre class="programlisting">
#include &lt;string.h&gt;

#include &lt;mate-panel-applet.h&gt;
#include &lt;gtk/gtklabel.h&gt;

static gboolean
hello_applet_fill (MatePanelApplet *applet,
		   const gchar *iid,
		   gpointer     data)
{
        GtkWidget *label;

        if (strcmp (iid, "OAFIID:My_HelloApplet") != 0)
		return FALSE;

        label = gtk_label_new ("Hello World");
	gtk_container_add (GTK_CONTAINER (applet), label);

	gtk_widget_show_all (GTK_WIDGET (applet));

        return TRUE;
}


MATE_PANEL_APPLET_MATECOMPONENT_FACTORY ("OAFIID:My_HelloApplet_Factory",
                             PANEL_TYPE_APPLET,
                             "TheHelloWorldApplet",
                             "0",
                             hello_applet_fill,
                             NULL);
      </pre>
<p>The code here is very similar to writing a normal MateComponent
control. You define a factory using MATE_PANEL_APPLET_MATECOMPONENT_FACTORY(),
passing it a factory function like hello_applet_fill().
      </p>
<p>libmate-panel-applet automatically creates a #MatePanelApplet object
for you, passing this to your factory method. Here, you should fill
the applet with your widgets just like a #GtkBin. For example, if you
were writing a cdplayer applet you would create a #GtkHBox, pack the
hbox with the cdplayer buttons and in turn add the hbox to the applet.
      </p>
</div>
</div>
<div class="footer">
<hr>Generated by GTK-Doc V1.29</div>
</body>
</html>